package com.fishingwithme.infrastructure.dtos;

import com.fishingwithme.domain.common.AuditInfo;
import com.fishingwithme.domain.common.Location;
import com.fishingwithme.domain.spots.FishType;
import com.fishingwithme.domain.spots.SpotLvl;
import com.fishingwithme.domain.spots.SpotType;
import com.fishingwithme.domain.spots.WaterType;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

import static net.minidev.json.JSONArray.toJSONString;

@EqualsAndHashCode(callSuper = true)
@Data
@TableName("spot")
public class FishingSpotUpdateDto extends AuditInfo {
    private String description;
    private String distance;
    private List<FishType> fishTypes;
    private String fishTypesString;
    private String id;
    private Integer isFree;
    private List<Location> line;
    private String lineString;
    private Location location;
    private SpotLvl lvl;
    private String name;
    private Boolean parkingEasy;
    private List<String> pics;
    private String picsString;
    private Boolean secret;
    private List<SpotType> spotTypes;
    private String spotTypesString;
    private WaterType waterType;
    private Long updatedBy;
    private Boolean isForbidden;

    public static FishingSpotUpdateDto format(FishingSpotUpdateDto dto) {
        dto.setFishTypes(CommonUtils.convert(dto.getFishTypesString(), FishType.class));
        dto.setLine(CommonUtils.convert(dto.getLineString(), Location.class));
        dto.setPics(CommonUtils.convert(dto.getPicsString(), String.class));
        dto.setSpotTypes(CommonUtils.convert(dto.getSpotTypesString(), SpotType.class));
        return dto;
    }

    public FishingSpotUpdateDto toJson() {
        this.fishTypesString = toJSONString(this.fishTypes);
        this.lineString = toJSONString(this.line);
        this.spotTypesString = toJSONString(this.spotTypes);
        this.picsString = toJSONString(this.pics);
       return this;
    }

}
